< previous page page_374 next page >

Page 374
Now we need to relate this to the classes and objects youre already familiar with in Visual Basic. Lets think about forms and text boxes. Each form you create in a project can have different properties set; however, they are all derived from the same form class. Same with text boxestheyre also derived from the same class, but each one has different properties. Youre already familiar with classes and objects. Now all you need to do is learn what to use them for and how to create your own in Visual Basic.
Instantiation
Instantiation is the act of creating an object based on a class. In Visual Basic terms, this is the process of declaring the object and then using it in your program. When you instantiate an object in Visual Basic, it takes up memory and possibly resources in the system. If a class is a cookie cutter and the object is a cookie, then the process of creating the cookie based on the cookie cutter is instantiation.
In Visual Basic, an object is instantiated when the first property or method is called, or when you create a new instance of that class. Take the following code example:
9f31265bb40b592b1929e18a47ab28e5.gif
Sub TestObject ()
   Dim oEmp As Employee

   Set oEmp = New Employee  ' Creates object here

   oEmp.FirstName = "Bill"
End Sub
The object is instantiated on the line where the New keyword is used.
Properties
The concept of properties should not be new to you at this point. Youve used properties to affect the look or behavior of a particular form or control. Properties simply hold the data about the particular object. These properties are defined by the class to be used by each individual object instantiated by that class.
Properties may be either public or private. Public properties are those that are exposed for use by other objects or code in an application. For example, a form object has Top, Left, Width, and Height properties. These public properties can be changed from the Properties window of Visual Basic.

 
< previous page page_374 next page >

If you like this book, buy it!